package cn.coderwe.model;


import java.util.ArrayList;
import java.util.List;

/**
 * @author : coderwe
 */

public class MultiLevelBook {

    private final String bookName;
    private String bookWriter;
    private String level1Dir;
    private String level2Dir;
    private final List<String> contents = new ArrayList<>();
    private final List<Chapter> chapters = new ArrayList<>();
    private final List<Volume> volumes = new ArrayList<>();

    private final List<String> intros = new ArrayList<>();

    public MultiLevelBook(String bookName) {
        this.bookName = bookName;
    }

    public void setLevel1Dir(String level1Dir) {
        if (this.level1Dir != null) {
            chapters.add(new Chapter(this.level2Dir, new ArrayList<>(contents)));
            contents.clear();
            volumes.add(new Volume(this.level1Dir, new ArrayList<>(chapters)));
            chapters.clear();
            this.level2Dir = null;
        }
        this.level1Dir = level1Dir;
    }

    public void setLevel2Dir(String level2Dir) {
        if (this.level2Dir != null) {
            chapters.add(new Chapter(this.level2Dir, new ArrayList<>(contents)));
            contents.clear();
        }
        this.level2Dir = level2Dir;
    }

    public void addContent(String content) {
        if (level2Dir != null) {
            contents.add(content);
        }
    }

    public void addOver() {
        chapters.add(new Chapter(this.level2Dir, new ArrayList<>(contents)));
        contents.clear();
        volumes.add(new Volume(this.level1Dir, new ArrayList<>(chapters)));
        chapters.clear();
    }

    public List<Volume> getVolumes() {
        return volumes;
    }

    public String getBookWriter() {
        return bookWriter;
    }

    public void setBookWriter(String bookWriter) {
        this.bookWriter = bookWriter;
    }

    public void addIntro(String intro){
        intros.add(intro);
    }

    public List<String> getIntros() {
        return intros;
    }

    public String getBookName() {
        return bookName;
    }
}
